/**
 * 流程决策
 * @param {Object} records
 */

var resultStore = null;
	/** 操作符 */
	var operatesStore = Ext.create('Ext.data.Store', {
	    fields: ['operateId', 'operateName'],
	    data:[
	    	{operateId:'==',operateName:'等于'},
	    	{operateId:'<', operateName:'小于'},
	    	{operateId:'<=',operateName:'小于等于'},
	    	{operateId:'>', operateName:'大于'},
	    	{operateId:'>=',operateName:'大于等于'}
	    ],
	    callback: function(records) { 
	   		operatesStore.setValue(value); //显示与value对应的text
	 	} 
	});
		
	resultStore = Ext.create('Ext.data.ArrayStore', {
		autoLoad:true,
		idProperty:'resId',
	    fields: [
	    	 {type:'string',name:'resId'},
	    	 {type:'string',name:'resName'}
	   	],
	   	root : "rows",
	    data:[
	//	    	{resId:'1',resName:'1'},
	//	    	{resId:'2',resName:'2'}
	    ]
	});

	//决策节点
	var decisionPanel = Ext.create('Ext.form.Panel', {
		id: 'decision',
		border: false,
		//layout : 'column',
		layout: {
	        type: 'table',
	        columns: 4
	    },
		width:550,
		bodyPadding: 2,
		bodyStyle: {background:"#dfe7f4",padding:"5 0 0 20"},
		//frame : true,
		fieldDefaults: {
			labelAlign: 'right',
			labelWidth: 65
	 	},
	 	defaults: { frame: false, width: 180, height: 40 },
		items: [{
			//columnWidth:.2,
	        layout : 'form',
	        border:0,
	       // height : 100 ,
	        defaultType: 'textfield',
	        frame : true,
	        items:[{
	        	id: 'exprText',
				name : 'exprText',
				//width:80,
				fieldLabel: '变量名',
				enableKeyEvents: true
	        }]
		},{
			//columnWidth:.2,
			border:0,
			layout : 'form',
			frame : true,
	        items:[{
	        	xtype: 'combo',
				id: 'operates',	
				fieldLabel:'操作符',
				emptyText: '请选择',
				border: false,
				width:150,
				editable:false,
				displayField: 'operateName',
		    	valueField: 'operateId',
		    	hiddenName:'operateName',
				store : operatesStore
	        }]
		},{
			//columnWidth:.2,
			border:0,
			layout : 'form',
			frame : true,
	     	items:[{
	     		xtype: 'combo',
	        	id: 'toNode',
				name : 'toNode',
				fieldLabel:'转向节点',
				emptyText: '请选择',
				//border: false,
				width:150,
				editable:false,
				displayField: 'resName',
		    	valueField: 'resId',
		    	hiddenName:'resName',
				store : resultStore
	        }]
		},{
			//columnWidth:.4,
			border:0,
			frame : true,
			items:[{
				xtype: 'button',
				id:'addDecision',
				name:'addDecision',
				text:'新增'
			}]
		},{
			width:400,
			height:70,
			frame : true,
			colspan:3,
			border:0,
			items:[{
				layout:'fit',
				xtype: 'textarea',
				anchor : '100%'
			}]
		}]
	});	

Ext.onReady(function(){

	Ext.getCmp('paramCard').add(decisionPanel);

});

function setDecision(){

	Ext.getCmp('paramCard').layout.setActiveItem(Ext.getCmp('decision'));//显示面板
	//resultStore.loadData([{'resId':'2', 'resName':'2'}]);
	if(opts.curXmlNode != null){

		var _data = [];
		var nodes = opts.curXmlNode.getElementsByTagName("transition");
		for(i=0; i<nodes.length; i++){
			_data.push({'resId':''+nodes[i].getAttribute("name"), 'resName':''+nodes[i].getAttribute("to")});
		}	
		var obj = {rows:_data};
		resultStore.loadData(obj.rows, false);
	}
}
